Beginner's Must-Know: Linux Log File Viewing Commands

This article introduces 5 essential log viewing commands for Linux server beginners, applicable to daily problem diagnosis and monitoring. The core commands and their uses are as follows: 1. **tail**: View the end of a file. Use `-n 数字` to specify the number of lines, `-f` for real-time monitoring (e.g., website access logs), and `-q` to suppress the filename display. 2. **head**: View the start of a file. The `-n 数字` parameter specifies the number of lines, suitable for initial logs (e.g., system startup logs). 3. **cat**: Quickly view the entire content of small files. Use `-n`/`-b` to display line numbers. Not recommended for large files (risk of screen overflow). 4. **less**: Page through large files. Supports up/down navigation, search (`/关键词`), and `+G` to jump to the end. 5. **grep**: Filter content by keyword. Use `-n` to show line numbers, `-i` for case-insensitive matching, and `-v` for inverse filtering. Often combined with `tail` (e.g., `tail -f log | grep error`). Combination tips: For example, `tail -n 100 log | grep error` quickly locates errors, and `less +G log` jumps to the end of the log.

Read More